import 'package:aichat_flutter_wallet/module_common/utils/colors.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:shimmer/shimmer.dart';

class DAppTitle extends StatelessWidget {
  String title;
  bool showMore = false;
  bool showHotIcon = false;
  bool isLoading = false;
  final void Function() onClick;
  final Widget? rightDom;

  DAppTitle({
    super.key,
    required this.title,
    this.showMore = false,
    this.showHotIcon = false,
    this.isLoading = false,
    void Function()? onClick,
    this.rightDom,
  }) : onClick = onClick ?? (() {});

  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return Container(
      margin: EdgeInsets.only(left: 20.w, top: 15.w, right: 20.w),
      child: Row(
        mainAxisAlignment: MainAxisAlignment.spaceBetween,
        children: [
          if (isLoading)
            Shimmer.fromColors(
                baseColor: Color.fromRGBO(246, 246, 246, 1),
                highlightColor: Colors.grey.shade300,
                child: Container(
                  width: 56.w,
                  height: 18.w,
                  margin: const EdgeInsets.all(0),
                  decoration: BoxDecoration(
                    borderRadius: BorderRadius.circular(3),
                    color: Colors.grey,
                  ),
                )),
          if (isLoading && showMore)
            Shimmer.fromColors(
                baseColor: Color.fromRGBO(246, 246, 246, 1),
                highlightColor: Colors.grey.shade300,
                child: Container(
                  width: 56.w,
                  height: 18.w,
                  margin: const EdgeInsets.all(0),
                  decoration: BoxDecoration(
                    borderRadius: BorderRadius.circular(4.w),
                    color: Colors.grey,
                  ),
                )),
          if (!isLoading)
            Row(
              crossAxisAlignment: CrossAxisAlignment.center,
              children: [
                Text(
                  title,
                  style: TextStyle(
                      fontSize: 16.sp,
                      fontWeight: FontWeight.w500,
                      color: Color.fromRGBO(51, 51, 51, 1)),
                ),
                SizedBox(width: 4.w),
                if (showHotIcon)
                  Image.asset(
                    'assets/images/dapp/hot.png',
                    width: 18.w,
                    height: 18.w,
                  )
              ],
            ),
          if (showMore && !isLoading)
            Row(
              // crossAxisAlignment: CrossAxisAlignment.center,
              children: [
                InkWell(
                  overlayColor: MaterialStateProperty.resolveWith((states) {
                    return Colors.transparent;
                  }),
                  onTap: () {
                    onClick();
                  },
                  child: Text(
                    'more',
                    style: TextStyle(
                        fontSize: 14.sp,
                        fontWeight: FontWeight.w400,
                        color: AppColors.c_6A6A6A),
                  ),
                ),
                SizedBox(width: 2.w),
                Transform.translate(
                  offset: Offset(0, 1),
                  child: InkWell(
                    onTap: () {
                      onClick();
                    },
                    child: Image.asset(
                      'assets/images/dapp/black_arrow.png',
                      width: 12.w,
                      height: 13.w,
                    ),
                  ),
                ),
              ],
            ),
          if (rightDom != null)
            Container(
              child: rightDom,
            )
        ],
      ),
    );
  }
}
